home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 October / Macformat17.cdr / Shareware City / Education / RLaB / toolbox / toeplitz.r < prev    next >
Encoding:
Text File  |  1994-06-18  |  1.1 KB  |  52 lines  |  [TEXT/ttxt]

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    toeplitz ( C )
  4. //        toeplitz ( C , R )
  5.  
  6. //  Description:
  7.  
  8. //  The toeplitz function returns a non-symmetric Toeplitz matrix
  9. //  having C as its first column and R as its first row. `toeplitz(C)'
  10. //  is a symmetric (or Hermitian) Toeplitz matrix.   
  11.  
  12. //  See also hankel.r
  13. //-------------------------------------------------------------------//
  14.  
  15. // dependencies
  16.  
  17. rfile flipud
  18.  
  19. toeplitz = function ( c , r ) 
  20. {
  21.   local(c, r, nc, h, j, nr);
  22.  
  23.   if (class(c) != "num") { error ("toeplitz: Inputs must be numeric"); }
  24.  
  25.   c = c[:];
  26.   nc = length (c);
  27.  
  28.   if (!exist (r)) {
  29.     r = c;
  30.   else
  31.     if (class(r) != "num") { error ("toeplitz: Inputs must be numeric"); }
  32.     if (length (c) != length (r)) 
  33.     {
  34.       error ("toeplitz: Inputs must have the same length");
  35.     }
  36.     r = r[:];
  37.     if (c[1] != r[1]) 
  38.     {
  39.       error ("toeplitz: First element of row must match first element of column");
  40.     }
  41.   }
  42.  
  43.   r = flipud (r);
  44.   h = zeros (nc, nc);
  45.   h[;1] = c;
  46.   for (j in 2:nc) 
  47.   {
  48.     h[;j] = [r[nc-j+1:nc-1]; c[1:nc-j+1]];
  49.   }
  50.   return h;
  51. };
  52.